jq(document).ready(function(){
	var $buyCarShow=jq("#buyCarShow");
	jq.getJSON("BuyCarServlet","action=showCar",function(data){
		var countPay=0;
		for(var i=0;i<data.length;i++){
			$buyCarShow.append("<tr><td id=\"minzi\"><div class=\"c_s_img\"><img src=\"images/c_1.jpg\" width=\"73\" height=\"73\" /></div>"+data[i].name+"</td><td align=\"center\" id=\"yanse\">"+data[i].shuxin+"</td><td align=\"center\"><div class=\"c_num\"><input type=\"button\" onclick=\"jianUpdate1(jq(this));\" class=\"car_btn_1\" /><input type=\"text\" value=\""+data[i].number+"\" name=\"\" class=\"car_ipt\" />  <input type=\"button\" onclick=\"addUpdate1(jq(this));\" class=\"car_btn_2\" /></div></td><td align=\"center\" style=\"color:#ff4e00;\">￥"+data[i].totalPay+"</td><td align=\"center\">26R</td>" +
					"<td align=\"center\"><a href=\"javascript:;\" id=\""+data[i].name+"\" class=\"delCarPro\" >删除</a>&nbsp; &nbsp;<a href=\"#\">加入收藏</a></td></tr>");
			countPay=countPay+data[i].totalPay;
		}
		$buyCarShow.append("<tr height=\"70\"><td colspan=\"6\" style=\"font-family:'Microsoft YaHei'; border-bottom:0;\"><label class=\"r_rad\"><input type=\"checkbox\" name=\"clear\" checked=\"checked\" /></label><label class=\"r_txt\">清空购物车</label><span class=\"fr\">商品总价：<b style=\"font-size:22px; color:#ff4e00;\" id=\"zp\">￥"+countPay+"</b></span></td></tr><tr valign=\"top\" height=\"150\"><td colspan=\"6\" align=\"right\">" +
				"<a href=\"#\"><img src=\"images/buy1.gif\" /></a>&nbsp; &nbsp; <a href=\"BuyCar_Two.html\"><img src=\"images/buy2.gif\" /></a></td></tr>");
	});
	
	//右上角小购物车展示
	var $i_car=jq(".i_car");
	jq.getJSON("BuyCarServlet","action=showCar",function(data){
		var countPay=0;
		$i_car.append("<div class=\"car_t\">购物车 [ <span>"+data.length+"</span> ]</div>");
		$i_car.append("<div class=\"car_bg\"></div>");
		var $car_bg=jq(".car_bg");
		$car_bg.append("<div class=\"un_login\">还未登录！<a href=\"Login.jsp\" style=\"color:#ff4e00;\">马上登录</a> 查看购物车！</div>");
		for(var i=0;i<data.length;i++){
			$car_bg.append("<ul class=\"cars\"><li><div class=\"img\"><a href=\"#\"><img src=\"images/car1.jpg\" width=\"58\" height=\"58\" /></a></div><div class=\"name\"><a href=\"#\">"+data[i].name+"</a></div><div class=\"price\"><font color=\"#ff4e00\">"+data[i].totalPay/data[i].number+"</font> X"+data[i].number+"</div></li></ul>");
			countPay=countPay+data[i].totalPay;
		}
		$car_bg.append("<div class=\"price_sum\">共计&nbsp; <font color=\"#ff4e00\">￥</font><span>"+countPay+"</span></div><div class=\"price_a\"><a href=\"#\">去购物车结算</a></div>");
	});
	
	//删除购物车产品
	jq("#buyCarShow").on("click",".delCarPro",function(){
		var name=this.id;
		jq.get("BuyCarServlet","action=delCar&name="+name,function(data){
			if(data=="success"){ //数据库删除成功则低页面同时删除该条产品
				location.href="BuyCar.jsp";
			}
		},"text");
		
		
	})
	
});